package org.example.hikvisiontest;

import com.sun.jna.Native;
import org.example.hikvisiontest.config.osSelect;
import org.example.hikvisiontest.hksdk.HCNetSDK;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class HikvisionTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(HikvisionTestApplication.class, args);
    }

    @Bean
    public  HCNetSDK getHCNetSDK() {

        synchronized (HCNetSDK.class) {
            String strDllPath = "";
            try {
                if (osSelect.isWindows())
                    //win系统加载库路径
                    strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll";
                else if (osSelect.isLinux())
                    //Linux系统加载库路径
                    strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so";
                HCNetSDK hcNetSDK=  (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
                hcNetSDK.NET_DVR_SetLogToFile(3, "./sdklog", false);
                if (hcNetSDK.NET_DVR_Init())
                    return  hcNetSDK;
                else
                    return null;
            } catch (Exception ex) {
                System.out.println("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
                return null;
            }
        }
    }
}
